package com.lst.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lst.api.constant.DeleteEnum;
import com.lst.api.entity.BusinessPlace;
import com.lst.api.mapper.BusinessPlaceMapper;
import com.lst.api.service.IBusinessPlaceService;
import com.lst.api.vo.IsRentCodeAndNameVo;
import com.lst.tools.mybatis.service.impl.BaseService;
import com.lst.tools.mybatis.utils.ExpandSqlUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 经营场所管理表业务层实现
 *
 * @author Frank
 * @date 2019-12-30 10:31:37
 * @version: V1.0
 */
@Service
public class BusinessPlaceService extends BaseService<BusinessPlaceMapper, BusinessPlace> implements IBusinessPlaceService {

    @Override
    public List<IsRentCodeAndNameVo> listBusinessPlace() {
        QueryWrapper<BusinessPlace> queryWrapper = new QueryWrapper();
        queryWrapper.eq(BusinessPlace.IS_DELETE, DeleteEnum.DELETE_NO.getKey());
        queryWrapper
                .orderByAsc(ExpandSqlUtils.getIsNullOrderBy(BusinessPlace.SORT, false))
                .orderByAsc(BusinessPlace.SORT)
                .orderByDesc(BusinessPlace.CREATE_AT)
                .orderByDesc(BusinessPlace.ID);
        List<BusinessPlace> businessPlaces = super.list(queryWrapper);
        if (CollectionUtils.isEmpty(businessPlaces)) {
            return Collections.EMPTY_LIST;
        }
        return businessPlaces
                .stream()
                .map(item -> new IsRentCodeAndNameVo(item.getId().toString(), item.getTitle(), item.getIsRent()))
                .collect(Collectors.toList());
    }
}